package Offer.offer2016;

public class Test31 
{

	public static void main(String[] args) 
	{
         int[] array={1,-2,3,10,-4,7,2,-5};
         System.out.println(findGreatestOfSum(array));
	}
    public static int findGreatestOfSum(int[] array)
    {
    	boolean inValidInput=false;
    	if(array==null||array.length==0)
    	{
    		inValidInput=true;
    		return 0;
    	}
    	int sum=0;
    	int result=0;
    	for(int i =0;i<array.length;i++)
    	{
    		if(sum<=0)
    		{
    			sum=array[i];
    		}
    		else
    		{
    			sum+=array[i];
    		}
    		
    		if(sum>result)
    		{
    			result=sum;
    		}
    	}
    	return result;
    }
}
